package com.demo.timer;

import java.text.SimpleDateFormat;
import java.util.TimerTask;

/**
 * FileName: MyTimerTask.java
 * 创建一个新的定时器任务
 *
 * @author Pretty_Boy
 * @version 1.00
 * @Date 2018/9/2719:06
 */
public class MyTimerTask extends TimerTask {

    /** 任务名称 */
    private String name;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public MyTimerTask(String name) {
        this.name = name;

    }



    @Override
    public void run() {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss" );
        String now = format.format(System.currentTimeMillis());
        System.out.println("任务执行：" + name + now);
        try {
            Thread.sleep(2000L);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
